package handler

import (
	"awesomeProject/app/model"
	"awesomeProject/app/request"
	"awesomeProject/app/response"
	"awesomeProject/app/service"
	"github.com/gin-gonic/gin"
)

type ShopHandler struct{}

var (
	shopSrv service.ShopSrv
)

// QueryMap 店铺map
func (s *ShopHandler) QueryMap(ctx *gin.Context) {
	var req request.ShopMap
	_ = ctx.Bind(&req)
	// 店铺权限
	user, _ := ctx.Get("user")
	var shopIds []uint
	shopIds = user.(model.User).ShopIds
	if user.(model.User).CompanyId != 0 {
		if req.CompanyId == 0 {
			//req.CompanyId = user.(model.User).CompanyId
		}
	}

	//user = util.CurrentLogin(ctx)
	response.Result(ctx, shopSrv.QueryMap(shopIds, req.CompanyId, user.(model.User)))
	return
}

// QueryMap 店铺map
func (s *ShopHandler) QueryMapFull(ctx *gin.Context) {
	var req request.ShopMap
	_ = ctx.Bind(&req)
	// 店铺权限
	user, _ := ctx.Get("user")
	var shopIds []uint
	if user.(model.User).CompanyId != 0 {
		_, shopIds = shopSrv.QueryShopIdsByUserFull(user.(model.User))
		if req.CompanyId == 0 {
			//req.CompanyId = user.(model.User).CompanyId
		}
	}

	//user = util.CurrentLogin(ctx)
	response.Result(ctx, shopSrv.QueryMapFull(shopIds, req.CompanyId, user.(model.User)))
	return
}